/** Map entity base class.
@param c Character used for this entity.
@param fg Foreground color.
@param bg Background color.
@param blockWalk Does this entity block walkability?
@param blockVis Does this entity block visibility?
*/
function Entity(name, c, fg, bg, blockWalk, blockVis)
{
	this.name = name;
	this.article = "a";
	this.character = c;
	this.fg = fg;
	this.bg = bg;
	this.blockWalk = blockWalk;
	this.blockVis = blockVis;
	this.x = 0;
	this.y = 0;
	this.parent = null;
}
Entity.prototype =
{
	isEntity: true,
	serialize: function(s)
	{
		s.push(this.x, this.y);
	},
	deserialize: function(s)
	{
		this.y = s.pop();
		this.x = s.pop();
	},
	/** Called when an entity tries to use this entity.
	@param user The entity using this entity.
	@param target The entity being used on (optional).
	*/
	use: function(user, target)
	{
	},
	/** Called when the entity arrives at a position on the sector map.
	 *@param isLoad True if this call was the result of map generation or loading, false otherwise.
	 */
	onArriveAtPosition: function(isLoad)
	{
	},
	/** Called when the entity leaves a position on the sector map.
	 */
	onLeavePosition: function()
	{
	}
};
Entity._ctors = {};
Entity.registerCtor = function(ctor, id)
{
	if(Entity._ctors[id] !== undefined)
		throw new Error("Duplicate CTOR id " + id);
	ctor.prototype.__serializationId = id;
	Entity._ctors[id] = ctor;
}
Entity.objectFromCtor = function(id)
{
	var ctor = Entity._ctors[id];
	if(ctor === undefined)
		throw new Error("Unregistered CTOR id requested " + id);
	return new ctor();
}
/** Returns the serialized form of an Entity.
@param ent The entity to serialize.
*/
Entity.getSerializedForm = function(ent)
{
	var ret = [];
	ent.serialize(ret);
	ret.push(ent.__serializationId);
	return ret;
}
/** Returns an entity object from a serailized form.
@param data The serialized form data array.
 */
Entity.fromSerializedData = function(data)
{
	var ctorId = data.pop();
	var ret = Entity.objectFromCtor(ctorId);
	ret.deserialize(data);
	return ret;
}
